using System.Linq;

namespace Core.Features
{
    using System;
    using Base;
    using Contracts.Enums;
    using Resources;
    using Core.Contracts.Interfaces;

    
    public sealed class RemoteArmorRepairAccumulatorUsage<T> : FeatureBase<object>
    {
        public RemoteArmorRepairAccumulatorUsage(){}

        public RemoteArmorRepairAccumulatorUsage(T value) 
            : base(value){ }
        /// <summary>
        /// Obtains the feature name
        /// </summary>
        public override string Name
        {
            get { return "Accumulator usage"; }
        }
        /// <summary>
        /// Obtains the feature group
        /// </summary>
        public override FeatureGroupsEnum FeatureGroup { get { return FeatureGroupsEnum.Specific; } }
        /// <summary>
        /// Obtains the feature type
        /// </summary>
        public override FeaturesEnum FeatureType { get { return FeaturesEnum.RemoteArmorRepairAccumulatorUsage; } }
        /// <summary>
        /// Obtains or defines the feature unit
        /// </summary>
        public override string Unit { get { return Traduction.label_unit_AP; } }

        public override void SetModifiedValue(IAgent agent, IRobot robot)
        {
            if(agent ==null || robot ==null) return;

            double temp = 0;

            // Bonus from ArmorRepairersTunings
            temp = robot.Modules.Aggregate(
                temp, 
                (current, modifier) => current*(1 - Math.Abs(modifier.Value)), 
                FeatureTypesEnum.Module, 
                this.FeatureType,
                ModuleGroupsEnum.ArmorRepairersTunings);

            ModifiedValue = IsRounded
                              ? Math.Round(temp, 0, MidpointRounding.AwayFromZero)
                              : Math.Round(temp, 2);
        }
        
    }
}